package com.qf.controller;

import com.qf.constant.RabbitMQConstants;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 发送延迟消息
 * @author lixu
 */
@RestController
@RequestMapping("/mq")
public class MessageController {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    /**
     * 发送延迟消息
     */
    @GetMapping("/sendDelayMessage")
    public String sendDelayMessage(){

        rabbitTemplate.convertAndSend(
                "delayed_exchange",
                "routingKey","我是延迟消息",(message) -> {
                    message.getMessageProperties().setDelay(1000*30);//30 （延迟）
                    System.out.println("==发延迟消息的时间是:" + new Date());
                    return message;
                });

        return "OK";
    }

}
